package com.yyq.eduservice.controller.frontIndex;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yyq.eduservice.entity.EduCourse;
import com.yyq.eduservice.entity.EduTeacher;
import com.yyq.eduservice.service.EduCourseService;
import com.yyq.eduservice.service.EduTeacherService;
import com.yyq.result.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author yyq
 * @create 2021-04-25 10:37
 */
@CrossOrigin
@RestController
@RequestMapping("/eduservice/front")
public class FrontIndexController {
    @Autowired
    private EduTeacherService teacherService;

    @Autowired
    private EduCourseService courseService;


    //获取主页的八条热门课程和四名
    @GetMapping("/index")
    public R GetFrontIndex(){
        QueryWrapper<EduTeacher> wrapper=new QueryWrapper<>();
        wrapper.orderByDesc("id");
        wrapper.last("limit 4");
        List<EduTeacher> teacherList = teacherService.list(wrapper);

        QueryWrapper<EduCourse> wrapper1=new QueryWrapper<>();
        wrapper1.eq("status","Normal"); //已发布
        wrapper1.orderByDesc("id");
        wrapper1.last("limit 8");
        List<EduCourse> courseList = courseService.list(wrapper1);


        return R.ok().data("teacherList",teacherList).data("courseList",courseList);
    }
}
